package com.symbio.ishenapi.background.controller;

import com.symbio.ishenapi.background.model.TmHelp;
import com.symbio.ishenapi.background.model.TmHelpFaq;
import com.symbio.ishenapi.background.model.TmHelpJpg;
import com.symbio.ishenapi.background.model.TmOperationLog;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 帮助反馈
 */
@RequestMapping("/TmHelp")
public class TmhelpController extends BaseController {

    /**
     * 建议反馈
     * 添加数据到表中
     */
    public void saveHelp() {
        TmHelp tmBackUser = (TmHelp) getReqBodyObject(TmHelp.class);
        Date dt = new Date();
        //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
        tmBackUser.setCreateTime(sdf.format(dt));
        if (tmBackUser.getUserId() == null || "".equals(tmBackUser.getUserId())) {
            renderJsonError(40003, "患者编号");
        } else if (tmBackUser.getHelpText() == null || "".equals(tmBackUser.getHelpText())) {
            renderJsonError(40003, "反馈意见");
        } else {
            tmBackUser.save();  //保存数据到反馈基本表中:tm_help
            if (tmBackUser.getHelpJpg() != null && !"".equals(tmBackUser.getHelpJpg())) {
                String[] split = tmBackUser.getHelpJpg().split(",");
                for (int i = 0; i < split.length; i++) {
                    TmHelpJpg tmHelpJpg = new TmHelpJpg();
                    tmHelpJpg.setHelpId(tmBackUser.getId());  //设置父表ID (tm_help的主键ID)
                    tmHelpJpg.setCreateTime(tmBackUser.getCreateTime()); //设置创建时间
                    tmHelpJpg.setStatus("1");  //设置状态
                    tmHelpJpg.setUrl(split[i]);
                    tmHelpJpg.save();
                }
            }
            renderJsonError(40001, "反馈意见");
        }
    }


    public void findBack() {  //帮助与反馈的接口
        TmHelp tmBackUser = (TmHelp) getReqBodyObject(TmHelp.class);
        List<TmHelp> list= TmHelp.dao.selectBack(tmBackUser);
        renderJsonRet(list);
    }

    public void findFaq(){  //FAQ帮助与反馈带条件
        TmHelpFaq tmFaqUser =(TmHelpFaq) getReqBodyObject(TmHelpFaq.class);
        List<TmHelpFaq> list =TmHelpFaq.dao.selectFaq(tmFaqUser);
        renderJsonRet(list);
    }

   /*public void patientList(){  //患者列表
        TmPatientUser tmPatientUser=(TmPatientUser)getReqBodyObject(TmPatientUser.class);
        List<TmPatientUser> list=TmPatientUser.dao.findPatient();
        renderJsonRet(list);
    }*/

    /**
     * @Author jianghy
     * @Description 投诉与建议列表查询
     * @date
     * @return void
     */
   public void queryInfo(){
       String userName = getPara("userName");
       String userType = getPara("userType");
       if("".equals(userName)||userName==null){
           userName="%";
       }
       if("".equals(userType)||userType==null){
           userType="0";
       }
       Map map = TmHelp.dao.queryInfo(getQueryModel(),userType,userName);
       renderPageJsonRet(map.get("count"),map.get("data"));
   }
    /**
     * @Author jianghy
     * @Description 投诉与建议详细信息查询
     * @date
     * @return void
     */
    public void queryDetailedInfo(){
        String id = getPara("id");
        if(!"".equals(id)||id!=null){
            TmHelp th = new TmHelp();
            th.setId(new Long(id));
            th.setReadState("已读");
            th.update();
            Map map = TmHelp.dao.queryDetailedInfo(id);
            renderJson(map);
        }else {
            renderJsonError(40003, "查询");
        }
    }
}
